#region Using Statements
using Microsoft.Xna.Framework;
#endregion

namespace GalconGame
{
    /// <summary>
    /// The options screen is brought up over the top of the main menu
    /// screen, and gives the user a chance to configure the game
    /// in various hopefully useful ways.
    /// </summary>
    class OptionsMenuScreen : MenuScreen
    {
        #region Fields

        MenuEntry fullScreenMenuEntry;
        MenuEntry soundMenuEntry;
        MenuEntry controlMenuEntry;

        static bool fullScreenMode = false;
        static bool soundEffect = false;
        #endregion

        #region Initialization


        /// <summary>
        /// Constructor.
        /// </summary>
        public OptionsMenuScreen()
            : base("Options")
        {
            // Create our menu entries.
            fullScreenMenuEntry = new MenuEntry(string.Empty);
            soundMenuEntry = new MenuEntry(string.Empty);
            controlMenuEntry = new MenuEntry("Controls");
            

            SetMenuEntryText();

            MenuEntry back = new MenuEntry("Back");

            // Hook up menu event handlers.
            fullScreenMenuEntry.Selected += FullScreenMenuEntrySelected;
            soundMenuEntry.Selected += SoundMenuEntrySelected;
            controlMenuEntry.Selected += ControlMenuEntrySelected;

            back.Selected += OnCancel;
            
            // Add entries to the menu.
            MenuEntries.Add(fullScreenMenuEntry);
            MenuEntries.Add(soundMenuEntry);
            MenuEntries.Add(controlMenuEntry);            
            MenuEntries.Add(back);
        }


        /// <summary>
        /// Fills in the latest values for the options screen menu text.
        /// </summary>
        void SetMenuEntryText()
        {
            fullScreenMenuEntry.Text = "Full Screen: " + fullScreenMode.ToString();
            soundMenuEntry.Text = "Sound: " + soundEffect.ToString();
        }


        #endregion

        #region Handle Input


        /// <summary>
        /// Event handler for when the Ungulate menu entry is selected.
        /// </summary>
        void FullScreenMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            fullScreenMode = !fullScreenMode;
            SetMenuEntryText();
        }


        /// <summary>
        /// Event handler for when the Language menu entry is selected.
        /// </summary>
        void SoundMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            soundEffect = !soundEffect;
            SetMenuEntryText();
        }


        /// <summary>
        /// Event handler for when the Frobnicate menu entry is selected.
        /// </summary>
        void ControlMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            const string message = "This is game controls";

            MessageBoxScreen confirmQuitMessageBox = new MessageBoxScreen(message);

            confirmQuitMessageBox.Accepted += ConfirmMessageBoxAccepted;

            ScreenManager.AddScreen(confirmQuitMessageBox, ControllingPlayer);
            SetMenuEntryText();
        }

        void ConfirmMessageBoxAccepted(object sender, PlayerIndexEventArgs e)
        {
            LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(),
                                                           new OptionsMenuScreen());
        }
       
        #endregion
    }
}
